package cn.dansj.common.utils.enums;

import java.io.Serializable;
import java.net.URI;

public enum DbType implements Serializable {
    oracle, mysql, redis, sqlServer, postGreSql, db2, dm;

    public static DbType getDbType(String dbType) {
        if (dbType == null) {
            return null;
        }
        if (dbType.equalsIgnoreCase("rediss")) {
            return redis;
        }
        for (DbType db : DbType.values()) {
            if (db.name().equalsIgnoreCase(dbType)) {
                return db;
            }
        }
        return null;
    }

    public static DbType parseUrl(String url) {
        URI uri = URI.create(url);
        if (uri.getScheme().equals("jdbc")) {
            uri = URI.create(url.substring(5));
        }
        return getDbType(uri.getScheme());
    }

    private static final long serialVersionUID = GlobalEnv.SerialVersionUID;

}
